package com.batis.source.builder;

import com.batis.source.session.MYConfiguration;
import org.apache.ibatis.type.TypeAliasRegistry;

/**
 * @author isam2016
 * @create 2021-08-26 2:08 PM
 */
public abstract class BaseBuilder {

    protected final MYConfiguration configuration;
    protected final TypeAliasRegistry typeAliasRegistry; // todo 使用框架的

    public BaseBuilder(MYConfiguration configuration) {
        this.configuration = configuration;
        this.typeAliasRegistry = this.configuration.getTypeAliasRegistry();
    }

    protected Class resolveClass(String alias) {
        if (alias == null) return null;
        try {
            return resolveAlias(alias);
        } catch (Exception e) {
            throw new Error("Error resolving class . Cause: " + e, e);
        }
    }

    protected Class resolveAlias(String alias) {
        return typeAliasRegistry.resolveAlias(alias);
    }
}
